<?php

namespace app\merchant\controller;

use app\common\command\Baobiao;
use app\common\command\Tstatis;
use app\common\controller\ActionLogs;
use app\common\controller\AfterPayPutCard;
use app\common\controller\AfterPayPutCardTest;
use app\common\controller\Balance;
use app\common\controller\Balancet;
use app\common\controller\Bonus;
use app\common\controller\CardCustom;
use app\common\controller\CardMarke;
use app\common\controller\CardPut;
use app\common\controller\CardPuttest;
use app\common\controller\CreateNotify;
use app\common\controller\Helpinfo;
use app\common\controller\Level;
use app\common\controller\Leveltest;
use app\common\controller\Platurl;
use app\common\controller\TemplateMsg;
use app\common\controller\TemplateMsgt;
use app\common\controller\TestBase;
use app\common\controller\Wxoption;
use app\common\controller\Ydhwork;
use app\common\model\CardBirthdayCare;
use app\common\model\CardBirthdayCareLog;
use app\common\model\CardBizPut;
use app\common\model\CardBizPutLogMember;
use app\common\model\CardBonusPut;
use app\common\model\CardBonusRule;
use app\common\model\CardConsume;
use app\common\model\CardCzLog;
use app\common\model\CardFreecard;
use app\common\model\CardGeneral;
use app\common\model\CardGive;
use app\common\model\CardGivecardLog;
use app\common\model\CardGivePutCard;
use app\common\model\CardMember;
use app\common\model\CardPaycard;
use app\common\model\CardPaycardlog;
use app\common\model\CardQrcode;
use app\common\model\CardRankUserLog;
use app\common\model\CardShareLog;
use app\common\model\CardShareRule;
use app\common\model\CardShareUser;
use app\common\model\CardTimingPutUser;
use app\common\model\CardUrlDict;
use app\common\model\CardusCodeMaster;
use app\common\model\CardUserBonus;
use app\common\model\CardUserFee;
use app\common\model\CardUserGet;
use app\common\model\CardRank;
use app\common\model\Agent;
use app\common\model\CardUserGetAli;
use app\common\model\CardUserLog;
use app\common\model\CardUserRecLog;
use app\common\model\CardUserUpdate;
use app\common\model\CardCzgive;
use app\common\model\LoginCode;
use app\common\model\LoginUsers;
use app\common\model\MchStatis;
use app\common\model\MerchantCate;
use app\common\model\Mstatis;
use app\common\model\OpenTemplate;
use app\common\model\Paylog;
use app\common\model\PaymentCardPut;
use app\common\model\PaymentCardPutLog;
use app\common\model\PrintReceipt;
use app\common\model\ProfitAccount;
use app\common\model\ProfitList;
use app\common\model\Tklog;
use app\common\model\WxOpen;
use app\common\model\Momerchant;
use app\common\model\Merchant;
use app\common\model\System;
use app\common\controller\Carddate;
use app\common\controller\AdminBase;
use app\common\model\YdhOpen;
use app\index\controller\Adview;
use app\index\controller\Wxcard;
use app\mobile\controller\Cardacitvate;
use app\mobile\controller\Cardshop;
use Csv\Csv;
use think\Controller;
use think\Db;
use think\Debug;
use think\Log;
use think\Queue;
use think\Request;
use think\config;
use think\Session;
use Wechat\Wxobjopen;
use Weixinpay\Wxtk;
use Wnkj\WnCardObj;
use Wnkj\WnObj;

class Exportextend extends TestBase
{

    //导出卡券核销数据
    public function export_cardsconsum(){
        $map['top_mid'] = Session::get('login_top_mid');
        $CardGen = new CardGeneral();
        $card_ids = $CardGen->where($map)->column('card_id');
        //END
        if (!empty($param['search_date'])) {
            $search_time = explode(" - ", $param['search_date']);
            $start_date = strtotime($search_time[0]);
            $end_date = strtotime($search_time[1]);
        } else {
            $start_date = strtotime(date('Y-m-d'));
            $end_date = strtotime(date('Y-m-d H:i:s'));
        }
        //END
        $maps['a.card_id'] = array('in',$card_ids);
        $maps['a.create_time'] =array(array('egt', $start_date), array('elt', $end_date), "and");
        $wn_card_consume=new CardConsume();
        $list2=$wn_card_consume->alias('a')
            ->join('wn_card_general b','a.card_id=b.card_id','left')
            ->join('wn_merchant c','a.mid=c.id','left')
            ->join('wn_card_user_get d','a.openid=d.openid and d.card_type="MEMBER_CARD"','left')
            ->where($maps)->field('a.*,b.title as card_title,c.merchant as merchantname,d.nickname,d.name')->select();
        foreach($list2 as $ks=>$vs){
            $lists[$ks]['id'] = $vs['id'];
            $lists[$ks]['card_type'] = getcardtype($vs['card_type']);
            $lists[$ks]['card_title'] = $vs['card_title'];
            $lists[$ks]['merchantname'] = $vs['merchantname'];
            $lists[$ks]['nickname'] = $vs['nickname'];
            $lists[$ks]['name'] = $vs['name'];
            $lists[$ks]['code'] = $vs['code']."\t";
            $lists[$ks]['con_username'] = $vs['con_username'];
            $lists[$ks]['source'] = $vs['source'];
            $lists[$ks]['hx_fs'] = $vs['hx_fs'];
            $lists[$ks]['create_time'] = $vs['create_time']."\t";
        }
        $Csv = new Csv();
        $header = ['id', '卡券类型', '卡券名称', '门店', '微信昵称', '姓名', '券号', '核销人', '核销渠道', '核销方式', '核销时间']; //表头,名称可自定义
        $res = $Csv->put_csv($lists, $header);


        $re_param['return_code'] = "SUCCESS";
        $re_param['return_msg'] = "成功";
        $re_param['data']['filepath'] = $res;
        return $re_param;

    }



}
